package cool.taomu.toolkit.jooq

import com.google.auto.service.AutoService
import com.google.inject.AbstractModule
import com.google.inject.matcher.Matchers
import cool.taomu.toolkit.TaomuConfigure
import cool.taomu.toolkit.annotations.datasource.Ds
import cool.taomu.toolkit.jooq.provider.JooqContextProvider
import cool.taomu.toolkit.jooq.provider.JooqProvider
import cool.taomu.toolkit.platform.inter.IPlatform
import org.jooq.DSLContext

@AutoService(IPlatform)
class JooqPlugin implements IPlatform {

    override note() {
        "JOOQ ORM框架"
    }

    override packages() {
    }

    override module(TaomuConfigure configure) {
        new AbstractModule() {
            override void configure() {
                bind(DSLContext).toProvider(JooqProvider)
                // 绑定 JooqContextProvider 和 DataSourceSwitcher
                bind(JooqContextProvider).asEagerSingleton();
                var dss = new DataSourceSwitcher;
                binder.requestInjection(dss);
                bindInterceptor(Matchers.any(), Matchers.annotatedWith(Ds), dss);
            }
        }
    }

    override start() {
    }

    override init() {
    }
}
